package logic

import (
	"context"
	"vues/models/mysql"
	"vues/vuesrpc/internal/svc"
	"vues/vuesrpc/vuesrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LoginLogic) Login(in *vuesrpc.LoginRequest) (*vuesrpc.LoginResponse, error) {
	// todo: add your logic here and delete this line

	//result, _ := cache.Rdb.Get(l.ctx, "captcha"+in.Account).Result()
	//
	//if in.CaptchaCode != result {
	//	return nil, fmt.Errorf("图片验证码错误")
	//}
	//
	//s, _ := cache.Rdb.Get(l.ctx, "sendSms"+in.Account).Result()
	//if in.SmsCode != s {
	//	return nil, fmt.Errorf("短信验证码错误")
	//}

	var user mysql.User
	//if user.ID == 0 {
	//	return nil, fmt.Errorf("账号不存在")
	//}
	//
	//if user.Password != pkg.Md5(in.Password) {
	//	return nil, fmt.Errorf("密码错误")
	//}
	return &vuesrpc.LoginResponse{
		UserId: int64(user.ID),
	}, nil
}
